package com.apimanage.user;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;

import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 用户中心服务启动类
 *
 * @author API管理平台
 */
@SpringBootApplication
@EnableDubbo
@EnableDiscoveryClient
@ComponentScan(basePackages = {"com.apimanage.user", "com.apimanage.common"})
public class UserCenterApplication {
    
    private static final Logger logger = LoggerFactory.getLogger(UserCenterApplication.class);

    public static void main(String[] args) {
        // 添加随机延迟，避免多个服务同时启动时的竞争
        Random random = new Random();
        int delaySeconds = random.nextInt(10); // 0-9秒的随机延迟
        logger.info("启动延迟 {} 秒，以避免服务注册冲突", delaySeconds);
        
        try {
            TimeUnit.SECONDS.sleep(delaySeconds);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        
        SpringApplication.run(UserCenterApplication.class, args);
    }
}